<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('角色管理')" />
</head>
<body class="hold-transition skin-blue sidebar-mini layout-boxed">
<div class="wrapper">
    <th:block th:include="include :: headbar" />
    <th:block th:include="include :: sidebar" />
    <div class="content-wrapper">
        <section class="content-header">
            <h1>&nbsp;</h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="#">系统管理</a></li>
                <li class="active">角色管理</li>
            </ol>
        </section>
        <section class="content">
            <div class="box box-solid">
                <form class="box-header with-border form-inline" id="form">
                    <input type="text" class="form-control input-sm" placeholder="角色名称" name="roleName">
                    <button type="button" class="btn btn-success btn-sm btn-flat" onclick="$.table.search('form')"><i class="fa fa-search"></i> 搜索</button>
                </form>
                <div class="box-body">
                    <div class="btn-group-sm form-inline" id="toolbar" role="group">
                        <button type="button" class="btn btn-success btn-sm btn-flat" onclick="$.operate.add()"><i class="fa fa-plus"></i> 添加</button>
                        <button type="button" class="btn btn-primary btn-sm btn-flat" onclick="$.operate.edit()"><i class="fa fa-edit"></i> 修改</button>
                        <button type="button" class="btn btn-danger btn-sm btn-flat" onclick="$.operate.remove()"><i class="fa fa-remove"></i> 删除</button>
                    </div>
                    <table id="bootstrap-table" data-mobile-responsive="true"></table>
                </div>
            </div>
        </section>
    </div>
    <th:block th:include="include :: copyright" />
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var prefix = "/system/role";
    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + '/add',
            removeUrl: prefix + '/remove',
            updateUrl: prefix + '/edit/{id}',
            sortName: "role_sort",
            uniqueId: 'roleId',
            modalName: "角色",
            modalWidth: 500,
            modalHeight: 400,
            columns: [
                { checkbox: true },
                { title: "序号", formatter: function (value, row, index) { return $.table.serialNumber(index); }},
                { field: 'roleName', title: '角色名称' },
                { field: 'roleKey', title: '权限字符' },
                { field: 'roleSort', title: '显示顺序' },
                { title: '角色状态', align: 'center', formatter: statusFormatter }
                ]
        };
        $.table.init(options);
    });

    /* 角色状态显示 */
    function statusFormatter(value, row, index) {
        if (row.status == 1) {
            return '<i class=\"fa fa-toggle-on text-info fa-lg\" onclick="disable(\'' + row.roleId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-off text-info fa-lg\" onclick="enable(\'' + row.roleId + '\')"></i> ';
        }
    }

    /* 角色管理-停用 */
    function disable(roleId) {
        $.post(prefix + "/changeStatus", { "roleId": roleId, "status": 0 }, function(resp){
            $.table.refresh();
        });
    }

    /* 角色管理启用 */
    function enable(roleId) {
        $.post(prefix + "/changeStatus", { "roleId": roleId, "status": 1 }, function(resp){
            $.table.refresh();
        });
    }
</script>
</body>
</html>
